#include "stdafx.h"
#include "word_py_map.h"
#include "process_error.h"

#include "tabfile.h"
#include "string_func.h"

#define MAX_PYSTRING_LENGTH		(32)
#define MAX_PY_COUNT			(7)
#define CHINESE_WORD_START_OFFSET	(0x4E00)

struct PY_WORD
{
	unsigned char	ucCount;
	unsigned char	ucOffset[MAX_PY_COUNT];
	char			szString[MAX_PYSTRING_LENGTH];
};

#include "word_py_data.dat"

CWord2PyMap CWord2PyMap::ms_Instance;
extern PY_WORD g_WORD2PYList[];

CWord2PyMap::CWord2PyMap()
{
	m_nWordCount = sizeof(g_WORD2PYList) / sizeof(g_WORD2PYList[0]);
}

CWord2PyMap::~CWord2PyMap()
{
}

CWord2PyMap& CWord2PyMap::GetInstance(void)
{
	return ms_Instance;
}

int CWord2PyMap::GetPYCount(wchar_t chWord)
{
	int nWordIndex = chWord - CHINESE_WORD_START_OFFSET;
	PROCESS_ERROR(nWordIndex >= 0 && nWordIndex < m_nWordCount);

	return g_WORD2PYList[nWordIndex].ucCount;
Exit0:
	return 0;
}

const char* CWord2PyMap::GetPY(wchar_t chWord, int nIndex)
{
	int nWordIndex = chWord - CHINESE_WORD_START_OFFSET;
	PROCESS_ERROR(nWordIndex >= 0 && nWordIndex < m_nWordCount);
	PROCESS_ERROR(nIndex < g_WORD2PYList[nWordIndex].ucCount);

	return g_WORD2PYList[nWordIndex].szString + g_WORD2PYList[nWordIndex].ucOffset[nIndex];
Exit0:
	return NULL;
}
